import random


random.seed(2)

xmax = 10
xtgt = random.randint(1, xmax)
while True:
    try:
        x = int(input(f'请在1~{xmax}之间猜数：').strip())
        if not 1 <= x <= xmax:
            print(f'请输入在1~{xmax}之间的整数。')
            continue
        if x == xtgt:
            print('恭喜，你猜对了！')
            break
        elif x > xtgt:
            print('你猜大了')
        else:
            print('你猜小了')
    except ValueError:
        print('请按要求输入整数！')